﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace Nirvana
{
    /// <summary>
    /// 音频资源规则配置脚本
    /// </summary>
    [Serializable]
    public sealed class ModelMaterialsImportConfig
    {
#if UNITY_2019_1_OR_NEWER
        [SerializeField]
        private ModelImporterMaterialImportModeVariate materialImportMode;
#else
        [SerializeField]
        private BoolVariate importMaterials;
#endif
        [SerializeField]
        private ModelImporterMaterialLocationVariate materialLocation;
        [SerializeField]
        private ModelImporterMaterialSearchVariate materialSearch;
        [SerializeField]
        private ModelImporterMaterialNameVariate materialName;
        [SerializeField]
        private BoolVariate useSRGBMaterialColor;


        public void MatchRule(ModelImporter importer)
        {
#if UNITY_2019_1_OR_NEWER
            if (this.materialImportMode.IsHasValue())
            {
                importer.materialImportMode = this.materialImportMode.GetValue();
            }
#else
            if (importMaterials.IsHasValue())
            {
                importer.importMaterials = importMaterials.GetValue();
            }
#endif
            if (this.useSRGBMaterialColor.IsHasValue())
            {
                importer.useSRGBMaterialColor = this.useSRGBMaterialColor.GetValue();
            }
            if (this.materialLocation.IsHasValue())
            {
                importer.materialLocation = this.materialLocation.GetValue();
            }
            if (this.materialSearch.IsHasValue())
            {
                importer.materialSearch = this.materialSearch.GetValue();
            }
            if (this.materialName.IsHasValue())
            {
                importer.materialName = this.materialName.GetValue();
            }

#if UNITY_2019_1_OR_NEWER
            importer.SaveAndReimport(); //unity2019版本需要主动刷新
#endif
        }

    }
}

